Java Mine
ContentsIndexHome
PreviousUpNext
BitConverter.bytesToHex Method
Syntax
Java
public static String bytesToHex(byte[] bytes);

public static long toLongFromFourBytes(byte[] bytes, int index) throws Exception { byte[] array = new byte[8]; //System.arraycopy(bytes, 0, array, 4, bytes.length); array[4] = bytes[3]; array[5] = bytes[2]; array[6] = bytes[1]; array[7] = bytes[0]; ByteBuffer b = ByteBuffer.wrap(array); 

return b.getLong(); } public static long toLongFromUint32(byte[] bytes, int index) throws Exception { byte[] array = new byte[8]; // System.arraycopy(bytes, 0, array, 4, bytes.length); array[0] = (byte) 0; array[1] = (byte) 0; array[2] = (byte) 0; array[3] = (byte) 0; array[4] = bytes[index+0]; array[5] = bytes[index+1]; array[6] = bytes[index+2]; array[7] = bytes[index+3]; // ByteBuffer b = ByteBuffer.wrap(array); 

// return b.getLong(); long l = ((bytes[index+3] & 0xFF) << 56) | ((bytes[index+2] & 0xFF) << 48) | ((bytes[index+1] & 0xFF) << 40) | ((bytes[index+0] & 0xFF) << 32) | ((array[3] & 0xFF) << 24) | ((array[2] & 0xFF) << 16) | ((array[1] & 0xFF) << 8) | ((array[0] & 0xFF) << 0); 

return l;

Copyright (c) 2023. All rights reserved.
What do you think about this topic? Send feedback!